#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <algorithm>
#include<cstdio>
#include <vector>
using namespace std;
string dfs(string& s, int& u) {
    u++;
    vector<string> v;
    while (s[u] == '0') v.push_back(dfs(s, u));
    u++;
    sort(v.begin(), v.end());
    string ans = "0";
    for (string& ss : v) ans += ss;
    ans += '1';
    return ans;
}
int main() {
    int t;
    cin >> t;
    while (t--) {
        string a, b;
        cin >> a >> b;
        a = '0' + a + '1';
        b = '0' + b + '1';
        int ua = 0, ub = 0;
        string ra = dfs(a, ua), rb = dfs(b, ub);
        if (ra == rb) printf("same\n");
        else printf("different\n");
    }
    return 0;
}

